package cc.rboot.inject.helper;

import cc.rboot._core.holder.AppContextHolder;
import cc.rboot.inject.annotation.InjectService;
import com.baomidou.mybatisplus.extension.service.IService;

public class InjectServiceHelper {

    /**
     * 获取注入的默认Service，顺序如下：
     * 1、类注解@InjectService
     * 2、报错
     */
    public static IService<?> injectService(Class<?> clazz) {
        InjectService injectService = clazz.getAnnotation(InjectService.class);
        if (null != injectService) {
            return AppContextHolder.getBean(injectService.service());
        }

        throw new RuntimeException(clazz.getName() + "% 找不到BaseService, 请使用@InjectService注入");
    }
}